package com.taimanetworks.kafka;

import com.taimanetworks.kafka.parseTsp.GpsData;
import org.apache.flink.streaming.connectors.redis.common.mapper.RedisCommand;
import org.apache.flink.streaming.connectors.redis.common.mapper.RedisCommandDescription;
import org.apache.flink.streaming.connectors.redis.common.mapper.RedisMapper;

public class RedisFunction implements RedisMapper<GpsData> {
    // 定义保存数据到redis的命令，存成Hash表，hset sensor_temp id temperature
    @Override
    public RedisCommandDescription getCommandDescription() {
        return new RedisCommandDescription(RedisCommand.HSET, "car_signal");
    }

    @Override
    public String getKeyFromData(GpsData gpsData) {
        return gpsData.getVin();
    }

    @Override
    public String getValueFromData(GpsData gpsData) {
        //milleag+soc+longitu+latitute
        return gpsData.getMilleage()+"&&"+gpsData.getSoc()+"&&"+gpsData.getLongitude()+"&&"+gpsData.getLatitude()+"&&"+gpsData.getGps_time();
    }
}
